using System;
using System.Windows.Markup;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Common.Unity.Configuration
{
	[ContentProperty( "Instance" )]
	public class UnityInstance : IContainerConfigurationCommand
	{
		public string BuildName { get; set; }

		public Type Type { get; set; }

		public object Instance { get; set; }

		public LifetimeManager Lifetime { get; set; }

		public void Configure( IUnityContainer container )
		{
			var type = Type ?? ( Instance != null ? Instance.GetType() : null );
			container.RegisterInstance( type, BuildName, Instance, Lifetime ?? new ContainerControlledLifetimeManager() );
		}
	}
}